package com.codingxyz.simple.volatiles;

public class VolatileAtomicDemo {



    public static void main(String[] args) {


        MyData myData = new MyData();

        for (int i = 1; i <= 20; i++) {


            new Thread(()->{

                for (int j = 1; j <= 1000; j++) {
                    myData.addPlusPlus();
                }

            },String.valueOf(i)).start();

        }

        /*需要等待上面二十个线程计算完成后，再执行main函数取得最终计算结果*/
        while (Thread.activeCount()>2){
            Thread.yield();
        }

        System.out.println(Thread.currentThread().getName() + " \t 计算结果 ："+myData.number);
    }
}
